namespace Miya.Hellow.Editor
{
    /// <summary>
    /// 将资源按类型分类 发布资产..
    /// </summary>
    public static class Distributer
    {



        //public static void Distribute()
        //{
        //    var bundlePath = $"{Addressables.BuildPath}";

        //    Debug.Log($"[AddressabeDistributer.Distribute]...........................BEGIN");

        //    if (!Directory.Exists(bundlePath))
        //    {
        //        Debug.LogError($"[AddressabeDistributer.Distribute]: NoPath@{bundlePath}");
        //        return;
        //    }


        //    //预先处理号 保存OutApp 的资产文件夹..
        //    string path_outapp = Path.Combine(Addressables.BuildPath, "OutApp");
        //    if (!Directory.Exists(path_outapp))
        //        Directory.CreateDirectory(path_outapp);


        //    // 分门别类的 处理所有 资产包...InAPP Primary Secondary OnCloud
        //    var bundles = Directory.GetFiles(bundlePath, "*.bundle", SearchOption.AllDirectories);
        //    foreach (var one in bundles)
        //    {
        //        var filename = Path.GetFileName(one);


        //        if (filename.StartsWith(AddressablePro.PrefixOf( DistributeType.Primary)))// 是否是首要资产
        //        {
        //            File.Move(one, Path.Combine(path_outapp, filename));
        //           // _Bundles_Primary.Add(one);
        //        }
        //        else if (filename.StartsWith(AddressablePro.PrefixOf(DistributeType.Secondary)))// 是否是次要资产
        //        {
        //            File.Move(one, Path.Combine(path_outapp, filename));
        //            //_Bundles_Secondary.Add(one);
        //        }
        //        else if (filename.StartsWith(AddressablePro.PrefixOf(DistributeType.OnCloud)))// 是否是云端资产
        //        {
        //            File.Move(one, Path.Combine(path_outapp, filename));
        //            //_Bundles_OnCloud.Add(one);
        //        }
        //        else 
        //        {
        //           // _Bundles_InApp.Add(one); // 预装包内
        //        }
        //    }
        //}


        ///// <summary>
        ///// 将资源上传到文件服务器
        ///// </summary>
        //public IEnumerator UploadBundles()
        //{
        //    if (_uploader == null)
        //    {
        //        yield break;
        //    }

        //    var uploadFiles = new List<string>();
        //    uploadFiles.AddRange(_All_InApp);
        //    uploadFiles.AddRange(_hotBundles);
        //    uploadFiles.AddRange(_dynamicBundles);
        //    uploadFiles.AddRange(_remoteBundles);

        //    var catalogPath = $"{Addressables.BuildPath}/catalog.json";
        //    uploadFiles.Add(catalogPath);

        //    _uploader.Upload(uploadFiles);
        //    while (!_uploader.Done)
        //    {
        //        yield return null;
        //    }

        //    Debug.Log($"{LogTag} upload completed!");
        //}

        /// <summary>
        /// 打包前的处理
        /// 只在打App的时候调用
        /// 删除Remote和Dynamic文件（不随包发布）
        /// </summary>
        //public void ProcBeforeBuildPlayer()
        //{
        //    var deleteFiles = new List<string>();
        //    deleteFiles.AddRange(_Bundles_Primary);
        //    deleteFiles.AddRange(_Bundles_Secondary);
        //    deleteFiles.AddRange(_Bundles_OnCloud);

        //    foreach (var deleteFile in deleteFiles)
        //    {
        //        DeleteFile(deleteFile);
        //    }

        //    Debug.Log($"{LogTag} proc before build player completed!");
        //}

        //private void DeleteFile(string file)
        //{
        //    if (File.Exists(file))
        //    {
        //        File.Delete(file);
        //        Debug.Log($"{LogTag} proc before build player delete file {file}");
        //    }
        //}
    }
}